

<script type="text/javascript">
	function test () {
		//var this = Object.create(test.prototype);
		//{
		//	__proto__ :test.prototype
		//}
	}

	new test();
</script>



函数预编译过程	this 指向window
全局作用域里this --> window

call/apply可以改变函数运行时this指向

obj.func(),谁调用方法,this指向谁obj

<script type="text/javascript">
	var obj = {
		a : function(){
			console.log(this.name)
		},
		name : 'asd'
	}

	obj.a();//obj调用的a方法，执行a方法，打印this.name,this指向obj
</script>

<script type="text/javascript">
	var name = '222';
	var a = {
		name : '111',
		say : function(){
			console.log(this.name);
		}
	}
	var fun = a.say;
	fun();//222
	a.say();//111

	var b = {
		name : '333',
		say : function(fun){
			console.log(this);
			a.say();//111
			fun();//222
			test();//test在函数体内，走预编译环节，没通过调用，this指向window
		}
	}



	function test(){
		console.log(this)
	}

	b.say(a.say);//在b.say里面执行a.say方法，走预编译环节，this指向window,打印222
	b.say = a.say;//把a.say方法给b.say
	b.say();//调用b.say方法，this指向b,打印333
</script>
